/**
 * 神州信息(2012)
 */
package net.abbp.watchkeeper;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import net.abbp.dao.DaoFactory;
import net.abbp.dao.IDao;
import net.abbp.dao.condition.Cnds;

/**
 * 联系
 * 
 * @version 1.0
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since ABBP 1.0
 * 
 *        Date：2012-2-4
 */
public enum WatchKeeperManager {
    INSTANCE;

    private IDao dao;

    WatchKeeperManager() {
        dao = DaoFactory.INSTANCE.newDao();
    }

    public List<Linkman> getLinkmans() {
        List<Linkman> lnks = dao.query(Linkman.class, Cnds.and("receive", "接收短信"));

        List<Linkman> ls = new ArrayList<Linkman>();
        ls.addAll(lnks);

        // 查找值班人员
        Linkman linkman = this.getWatchKeeper();
        if (linkman != null) {
            ls.add(linkman);
        }

        return ls;
    }

    /**
     * 获取值班人员
     * 
     * @return
     */
    private Linkman getWatchKeeper() {
        Calendar cal = Calendar.getInstance();
        int day = cal.get(Calendar.DAY_OF_WEEK);
        WatchkeeperInfo info = dao.fetch(WatchkeeperInfo.class);

        String man = "";
        switch (day) {
        case Calendar.SUNDAY:
            man = info.getF7();
            break;
        case Calendar.MONDAY:
            man = info.getF1();
            break;
        case Calendar.TUESDAY:
            man = info.getF2();
            break;
        case Calendar.WEDNESDAY:
            man = info.getF3();
            break;
        case Calendar.THURSDAY:
            man = info.getF4();
            break;
        case Calendar.FRIDAY:
            man = info.getF5();
            break;
        case Calendar.SATURDAY:
            man = info.getF6();
            break;
        }

        return dao.fetch(Linkman.class, Cnds.and("name", man));
    }
}
